<template>
	<view >
		<view v-if="!orderCurrentList.length" >
			
		</view>
		<view style="background-color: gray;padding-bottom: 20%;">
			<uni-title>待制作订单</uni-title>
			<view  v-for="(value,key,index) in total_list" class="list">
				<view  style="padding: 20rpx;border-radius: 30rpx;width: 720rpx;background-color: white;display: flex;flex-direction: column;align-items: center;">
					<span >订单号：{{key.slice(1,key.length)}}</span>
					<view v-for="(item,index) in value" style="width: 600rpx;" >
						<view style="display: flex;margin-top: 30rpx;">
							<image :src="item.image_name" style="width: 150rpx;height: 220rpx;"></image>
							<view style="height: 220rpx;width: 500rpx;display: flex;justify-content: space-between;">
								<view style="display: flex;flex-direction: column;height: 220rpx;justify-content: space-around;">
									<span style="color: black;font-size: 35rpx;font-weight: bold;">{{item.name}}</span>
									<span style="font-size: 30rpx;color: darkgray">{{item.detail}}</span>
									<span style="font-size: 30rpx;color: green;">×{{item.num}}</span>
								</view>
								<view style="height: 100%;display: flex;flex-direction: column;justify-content: space-between;">
									<span style="color: green;font-size: 35rpx;font-weight: bold;margin-top: 20rpx;">￥{{item.price}}</span>
									<span style="color: green;font-size: 35rpx;font-weight: bold;margin-bottom: 10%;">{{item.status}}</span>
								</view>
								
							</view>
							
						</view>
						
					</view>
					<view style="display: flex;flex-direction: row;">
						<button @click="finish(key.slice(1,key.length))">制作完成</button>
						<button @click="cancel(value)">删除订单</button>
					</view>
				</view>
				
			</view>
		</view>
		<view class="nav">
			<view class="item" @click="skipToKitchen()">
				<image src="../../../static/点单.png" class="pic"></image>
				<span class="word">厨房</span>
			</view>
			<view class="item" @click="skipToTotalItems()">
				<image src="../../../static/点单.png" class="pic"></image>
				<span class="word">仓库</span>
			</view>
			<view class="item" @click="skipToAddItem()">
				<image src="../../../static/首页.png" class="pic" style="margin-left: 18rpx;"></image>
				<span class="word">新增</span>
			</view>
			
			
		</view>
		</view>
	</view>
</template>

<script>
	import nav1 from "../navv/nav1.js"
	import emptyOrder from "../myorder/emptyOrder/emptyOrder.vue"
	export default {
		data() {
			return {
				status:true,
				orderCurrentList:[],
				total_list:{}
			}
		},
		methods: {
			...nav1,
			cancel(value){
				let t=this
				let obj={value:value}
				uni.showModal({
					title: '提示',
					content: '确定删除吗？',
					success(res) {
						if(res.cancel){
							
						}else{
							uni.request({
								url:"http://localhost:3000/delCurrentOrder",
								method:"POST",
								dataType:"json",
								data:JSON.stringify(obj),
								success(data) {
									// uni.reLaunch({
									// 	url:"/pages/index/kitchen/kitchen"
									// })
									uni.request({
										url:"http://localhost:3000/insertHistoryOrder",
										data:JSON.stringify(obj),
										method:"POST",
										dataType:"application/json",
									})
									uni.reLaunch({
										url:"/pages/index/kitchen/kitchen"
									})
								}
							
							});
						}
						
					}
				})
				
			},
			finish(msg){
				let t=this
				let obj={msg:msg}
				console.log(this.total_list)
				uni.request({
					url:"http://localhost:3000/finishCurrentOrder",
					method:"POST",
					dataType:"json",
					data:obj,
					success(data) {
						uni.reLaunch({
							url:"/pages/index/kitchen/kitchen"
						})
					}

				});
			},
			
		},
		components:{
			emptyOrder
		},
		created() {
				
			var t=this
			uni.request({
				url:"http://localhost:3000/getCurrentOrders",
				success(data) {
					//console.log(data.data)
					
					t.orderCurrentList=data.data
					let single_list=[]
					
					for(let i=0;i<t.orderCurrentList.length;i++){
						
						if(single_list.indexOf(t.orderCurrentList[i].order_id)==-1){
							single_list.push(t.orderCurrentList[i].order_id)
						}
					}
					single_list=single_list.reverse()
					for(let i=0;i<single_list.length;i++){
						let items=[]
						for(let ii=0;ii<t.orderCurrentList.length;ii++){
							if(t.orderCurrentList[ii].order_id==single_list[i]){
								items.push(t.orderCurrentList[ii])
							}
						}
						console.log("",items);
						t.$set(t.total_list,"l"+single_list[i],items)
						
					}
					
					console.log("333333333",t.total_list);
				}
			})
		},
		
	}
</script>

<style>
.nav{
		display: flex;
		position: fixed;
		position: fixed;
		top:92%;
		background-color: white;
		flex-direction: row;
		justify-content: space-around;
		align-items: center;
		width: 750rpx;
		height: 120rpx;
		border-top: 2rpx;
		border-style: solid;
		border-width: 2rpx;
		border-color: #d0d0d0;
		z-index: 99;
	}
	.pic{
		width: 60rpx;
		height: 80rpx;
	}
</style>
